﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.DataVisualization.Charting;
using System.Web.UI.WebControls;

public partial class Charts_Pie_CentersUsage : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void ChartLinkButton_Click(object sender, EventArgs e)
    {
        SetCentersHiddenField();

        DataView dataView = new DataView();
        DataTable dataTable = new DataTable();
        dataView = CentersUsageSqlDataSource.Select(DataSourceSelectArguments.Empty) as DataView;
        if (dataView != null)
        {
            dataTable = dataView.ToTable();
            float[] yValues = new float[dataTable.Rows.Count];
            string[] xValues = new string[dataTable.Rows.Count];

            for (int i = 0; i < dataTable.Rows.Count; i++)
            {
                if (float.Parse(dataTable.Rows[i][2].ToString()) > 0)
                {
                    xValues[i] = dataTable.Rows[i][1].ToString();
                    yValues[i] = float.Parse(dataTable.Rows[i][2].ToString());
                }
            }

            Chart1.Series["Default"].Points.DataBindXY(xValues, yValues);
            Chart1.Series["Default"].ChartType = SeriesChartType.Pie;
            Chart1.Series["Default"]["PieLabelStyle"] = "Disabled";
            Chart1.ChartAreas["ChartArea1"].Area3DStyle.Enable3D = true;
            Chart1.Legends[0].Enabled = true;
        }
    }
    private void SetCentersHiddenField()
    {
        CenterIDHiddenField.Value = string.Empty;
        for (int i = 0; i < CenterCheckBoxList.Items.Count; i++)
            if (CenterCheckBoxList.Items[i].Selected)
                CenterIDHiddenField.Value += CenterCheckBoxList.Items[i].Value[0] + ",";
    }
}